/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package enteties.article;

import java.util.ArrayList;
import java.util.Collection;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import util.article.StockDetails;

/**
 *
 * @author Joris
 */
@Stateless
public class StockFacade extends AbstractFacade<Stock> implements StockFacadeLocal {
    @PersistenceContext(unitName = "Liebaut-ejbPU")
    private EntityManager em;
    
    @EJB
    private Size1Facade sizeFacade;
    
    @EJB
    private ModelFacade modelFacade;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public StockFacade() {
        super(Stock.class);
    }
    
    @Override
    public StockDetails convert (Stock s){
        if(s == null)
            return null;
        return new StockDetails(s.getId(), s.getYear(), s.getAmount(),
                sizeFacade.convert(s.getSizeid()), modelFacade.convert(s.getModelid()));
    }
    
    @Override
    public Collection<StockDetails> convert (Collection<Stock> stocks){
        Collection<StockDetails> details = new ArrayList<StockDetails>();
        for(Stock stock : stocks){
            details.add(convert(stock));
        }
        return details;
    }
    
}
